import { ApiProperty } from '@nestjs/swagger';
import {
  IsDate,
  IsEmail,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString,
  IsUrl,
  Length,
} from 'class-validator';

export class UserDto {
  @IsNumber()
  @IsOptional()
  id?: number;

  @ApiProperty({ description: '用户名', required: true })
  @IsString()
  @IsNotEmpty({ message: '用户名不能为空' })
  username: string;

  @ApiProperty({ description: '密码', maxLength: 6, minLength: 6 })
  @IsString()
  @IsNotEmpty({ message: '密码不能为空' })
  @Length(6, 6, { message: '密码长度必须为6位' })
  password: string;

  @ApiProperty({ description: '别名' })
  @IsString()
  @IsOptional()
  nickname: string;

  @ApiProperty({ description: '邮箱' })
  @IsEmail({}, { message: '邮箱格式不正确' })
  @IsOptional()
  email: string;

  @ApiProperty({ description: '用户头像' })
  @IsUrl({}, { message: 'url地址不正确' })
  @IsOptional()
  user_pic?: string;

  @ApiProperty({ description: '创建日期' })
  @IsDate()
  @IsOptional()
  created_time?: Date;

  @ApiProperty({ description: '更新日期' })
  @IsDate()
  @IsOptional()
  update_time?: Date;
}

export class UserLoginDto {
  @ApiProperty({ description: '用户名', required: true })
  @IsString()
  @IsNotEmpty({ message: '用户名不能为空' })
  username: string;

  @ApiProperty({ description: '密码', maxLength: 6, minLength: 6 })
  @IsString()
  @IsNotEmpty({ message: '密码不能为空' })
  @Length(6, 6, { message: '密码长度必须为6位' })
  password: string;
}

export class UserUpdateDto {
  @IsNumber()
  id: number;

  @IsString()
  @IsOptional()
  username?: string;

  @IsString()
  @IsOptional()
  nickname?: string;

  @IsEmail({}, { message: '邮箱格式不正确' })
  @IsOptional()
  email?: string;

  @IsUrl({}, { message: '图片地址格式不正确' })
  @IsOptional()
  user_pic?: string;

  @IsString()
  @IsNotEmpty({ message: '密码不能为空' })
  @Length(6, 6, { message: '密码长度必须为6位' })
  @IsOptional()
  password?: string;
}

export class UserUpdatePwdDto {
  @IsNumber()
  @IsOptional()
  id?: number;

  @IsString()
  @IsNotEmpty({ message: '旧密码不能为空' })
  @Length(6, 6, { message: '旧密码长度必须为6位' })
  old_pwd: string;

  @IsString()
  @IsNotEmpty({ message: '新密码不能为空' })
  @Length(6, 6, { message: '新密码长度必须为6位' })
  new_pwd: string;

  @IsString()
  @IsNotEmpty({ message: '重复密码不能为空' })
  @Length(6, 6, { message: '重复密码长度必须为6位' })
  re_pwd: string;
}
